// BOUJEDLI Najim
// PANERI Jérémy
// M1S8 Info
// MOIA Génétique

import java.util.Scanner;

public class GA {
	public static void main(String[] args) {
		
		int sizePop;
		float rateMutation;
		float rateCroisement;
		int nbIterations;

		// Saisie des paramètres
		Scanner sc = new Scanner(System.in);

		System.out.print("Taille de la population :\t");
		sizePop = sc.nextInt();
		System.out.print("Taux de mutation :\t\t");
		rateMutation = sc.nextFloat();
		System.out.print("Taux de croisement :\t\t");
		rateCroisement = sc.nextFloat();
		System.out.print("Nombre d'iterations :\t\t");
		nbIterations = sc.nextInt();
		System.out.println();


		// Création et initialisation de la population
		Population myPop = new Population(sizePop, true);

		for(int i=0 ; i<sizePop ; i++) {
			myPop.getIndividual(i).getFitness();
		}


		// Évolution de la population
		for(int gen=1 ; gen<=nbIterations ; gen++) {
			System.out.println("\n- Generation "+ gen +" -");

			Individual bestIt = myPop.getFittest();
			System.out.println("Meilleur individu :\t"+ bestIt);
			System.out.println("Fitness :\t\t"+ bestIt.getFitness());
			System.out.println("Fitness moyen :\t\t"+ myPop.getAvgFitness());

			myPop = Algorithm.evolvePopulation(myPop, rateMutation, rateCroisement);
		}

		
		// Bilan des itérations
		Individual best = myPop.getFittest();
		double fit = best.getFitness();
		double d1 = FitnessCalc.getD1(best);
		double d2 = FitnessCalc.getD2(best);

		System.out.println("\n\nMEILLEUR INDIVIDU");
		System.out.println("Genes :\t\t"+ best);
		System.out.println("Fitness :\t"+ fit);
		System.out.println("Surface :\t"+ fit*Math.PI/4);
		System.out.println("D1 :\t\t"+ d1);
		System.out.println("D2 :\t\t"+ d2);
		System.out.print("D3 :\t\t"+ (100-d1-d2));
	}
}
